<?php
// 显示所有错误
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$results = [];
$success = true;

// 修复AdminAuth.php中的路径
$authFile = __DIR__ . '/includes/AdminAuth.php';
if (file_exists($authFile)) {
    $content = file_get_contents($authFile);
    // 将 '/../../include/Database.php' 改为 '/../include/Database.php'
    $newContent = str_replace("'/../../include/Database.php'", "'/../include/Database.php'", $content);
    
    if ($content !== $newContent) {
        file_put_contents($authFile, $newContent);
        $results[] = "已修复 AdminAuth.php 中的路径";
    } else {
        $results[] = "AdminAuth.php 中的路径似乎没有问题";
    }
} else {
    $success = false;
    $results[] = "无法找到 AdminAuth.php 文件";
}

// 修复header.php中的路径
$headerFile = __DIR__ . '/includes/header.php';
if (file_exists($headerFile)) {
    $content = file_get_contents($headerFile);
    // 将 '/../../include/Database.php' 改为 '/../include/Database.php'
    $newContent = str_replace("'/../../include/Database.php'", "'/../include/Database.php'", $content);
    
    if ($content !== $newContent) {
        file_put_contents($headerFile, $newContent);
        $results[] = "已修复 header.php 中的路径";
    } else {
        $results[] = "header.php 中的路径似乎没有问题";
    }
} else {
    $success = false;
    $results[] = "无法找到 header.php 文件";
}

?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>KidsMind - 修复路径问题</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css">
</head>
<body>
    <div class="container mt-5">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card shadow">
                    <div class="card-header bg-primary text-white">
                        <h4 class="mb-0">KidsMind 路径修复工具</h4>
                    </div>
                    <div class="card-body">
                        <h5 class="card-title mb-4">修复结果</h5>
                        
                        <?php foreach ($results as $result): ?>
                            <div class="alert alert-info"><?php echo $result; ?></div>
                        <?php endforeach; ?>
                        
                        <?php if ($success): ?>
                            <div class="alert alert-success"><strong>修复完成！</strong> 现在您可以尝试访问管理后台。</div>
                        <?php else: ?>
                            <div class="alert alert-warning"><strong>注意！</strong> 部分文件无法找到，可能需要手动修复。</div>
                        <?php endif; ?>
                        
                        <div class="mt-4">
                            <a href="index.php" class="btn btn-primary">进入管理后台</a>
                            <a href="debug_pages.php" class="btn btn-secondary">运行诊断</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html> 